<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 面包屑导航End -->

    <el-card>
      <!-- 搜索框 -->
      <el-row>
        <el-col :span="8">
          <el-input placeholder="请输入内容">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 搜索框End -->

      <!-- 数据表格 -->
      <el-table :data="ordersList" border stripe class="mt-15">
        <el-table-column type="index"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column
          prop="order_price"
          label="订单价格"
          width="120"
        ></el-table-column>
        <el-table-column prop="pay_status" label="是否付款" width="120">
          <template slot-scope="slot">
            <el-tag type="danger" v-if="slot.row.order_pay">未付款</el-tag>
            <el-tag type="success" v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          prop="is_send"
          label="是否发货"
          width="120"
        ></el-table-column>
        <el-table-column label="下单时间" width="200">
          <template slot-scope="scope">
            <span>{{ scope.row.create_time | timestamp2Date }}</span>
          </template>
        </el-table-column>
        <el-table-column prop="ordersList" label="操作" width="140">
          <template slot-scope="scope">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="orderEditDialog"
            ></el-button>
            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
              @click="orderLocaltionDialog(scope.row)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 数据表格End -->

      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="ordersData.pagenum"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="ordersData.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="ordersTotal"
        class="mt-15"
      >
      </el-pagination>
      <!-- 分页End -->
    </el-card>

    <!-- 修改订单地址 -->
    <el-dialog
      title="修改地址"
      :visible.sync="editLocalDialogVisible"
      width="50%"
    >
      <el-form
        label-width="100px"
        :model="editOrderInfos"
        :rules="editOrderInfosRules"
      >
        <el-form-item label="省市区/县" prop="selectAddressOptions">
          <el-cascader
            expand-trigger="hover"
            :options="cityOptions"
            v-model="editOrderInfos.selectAddressOptions"
            placeholder="请选择"
            @change="selectedOptions"
          >
          </el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="orderDetailAddr">
          <el-input v-model="editOrderInfos.orderDetailAddr"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editLocalDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editLocalDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 修改订单地址End -->

    <!-- 物流配送 -->
    <el-dialog
      title="物流进度"
      :visible.sync="progressDialogVisible"
      width="50%"
    >
      <span>这是一段信息</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="progressDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="progressDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 物流配送End -->
  </div>
</template>

<script>
import cityOptions from "@/assets/js/city_data2017_element.js";

export default {
  data() {
    return {
      // 订单参数
      ordersData: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      // 订单总数
      ordersTotal: 0,
      // 订单数据
      ordersList: [],

      // 修改地址对话框
      editLocalDialogVisible: false,
      progressDialogVisible: false,

      editOrderInfos: {
        // 级联地址选择
        selectAddressOptions: [],
        // 详细地址
        orderDetailAddr: "",
      },
      // 编辑订单规则
      editOrderInfosRules: {
        selectAddressOptions: [
          { required: true, message: "请选择省市区/县", trigger: "blur" },
        ],
        orderDetailAddr: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
      },

      cityOptions,
    };
  },
  created() {
    // 获取订单列表
    this.getOrdersListData();
  },
  methods: {
    // 获取订单列表
    async getOrdersListData() {
      let { data: res } = await this.$http(`orders`, {
        params: this.ordersData,
      });
      if (res.meta.status !== 200)
        return this.$message.error("获取订单列表失败");
      this.$message.success("获取订单列表成功");
      this.ordersList = res.data.goods;
      this.ordersTotal = res.data.total;
      console.log(res);
    },

    // 分页每页数目改变时触发
    handleSizeChange(val) {
      this.ordersData.pagesize = val;
      this.getOrdersListData();
    },
    // 分页改变当前页
    handleCurrentChange(val) {
      this.ordersData.pagenum = val;
      this.getOrdersListData();
    },

    // 订单修改对话框
    orderEditDialog() {
      this.editLocalDialogVisible = true;
    },
    // 订单物流进度
    async orderLocaltionDialog(payload) {
      // 请求不了数据
      // await this.$http
      //   .get("kuaidi/804909574412544580")
      //   .then((res) => {
      //     console.log(res.data);
      //   })
      //   .catch((error) => {
      //     console.log(error);
      //   });
      // 请求不了数据

      // 显示对话框
      this.progressDialogVisible = true;
      console.log(payload);
    },

    selectedOptions(val) {
      console.log(val);
    },
  },
};
</script>


<style scoped>
.el-cascader {
  width: 100%;
}
</style>